package fr.cnam.ratpProject.client.activities.lineMap;

import com.google.gwt.core.client.Callback;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.geolocation.client.Geolocation;
import com.google.gwt.geolocation.client.Position;
import com.google.gwt.geolocation.client.PositionError;
import com.google.gwt.maps.client.Maps;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;

import fr.cnam.ratpProject.client.utils.GlueProvider;
import fr.cnam.ratpProject.client.utils.RatpActivity;

public class LineMap extends RatpActivity{

	public interface LineMapView extends IsWidget {
		public void buildUi();
		public void buildUi(Position pos);

	}
	
	private LineMapView view;
	
	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		view = GlueProvider.INSTANCE.getClientFactory().getLineMapView();
		this.attachView(panel, view);
		
		Maps.loadMapsApi("", "2.0", true, new Runnable() {
			
			@Override
			public void run() {
					Geolocation.getIfSupported().getCurrentPosition(new Callback<Position, PositionError>() {
						
						@Override
						public void onSuccess(Position result) {
							view.buildUi(result);
						}
						
						@Override
						public void onFailure(PositionError reason) {
							view.buildUi();
						}
					});
			}
		});
		
	}

}
